#include <iostream>
#include <cstdio>

using namespace std;

class node {
   public:
       int fa;
       string s;
       int c[27];

}nd[100];

int n, nt;

void build(char *str) {
    int i = 0;
    int now = 0;
    while(str[i] != '\0') {
        if(nd[now].c[(int)str[i] - 'a' + 1]){
            now = nd[now].c[(int)str[i] - 'a' + 1];
			i++;
            continue;
        }
        nd[++nt].fa = now;
        nd[now].c[(int)str[i] - 'a' + 1] = nt;
        now = nd[now].c[(int)str[i] - 'a' + 1];
        nd[now].s = nd[nd[now].fa].s + str[i];
        i++;
    }
    return ;
}

int main() {
	freopen("in.txt", "r", stdin);
	
    cin >> n;
    for(int i = 1; i <= n; i++) {
        char str[100];
        cin >> str;
        build(str);
    }
    
    for(int i = 0; i <= nt; i++) {
    	cout << i << " " << nd[i].s << endl;
    }

}

